package com.dongway.netcondition.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.dongway.core.web.AbstractBaseController;
import com.dongway.netcondition.dto.AutoCompleteItem;
import com.dongway.netcondition.model.DevNetState;
import com.dongway.netcondition.service.DevNetStateService;
import com.dongway.netcondition.service.DevSelectHelper;

@Controller
public class ManagerController extends AbstractBaseController {

    @Autowired
    private DevSelectHelper devSelectHelper;
    @Autowired
    private DevNetStateService devStateService;


    @RequestMapping("/manager.htm")
    public String home(Integer branchId, ModelMap modelMap) {

        List<AutoCompleteItem> branches = devSelectHelper.getAllBranch();
        modelMap.put("branches", branches);
        if (branchId != null) {
            List<AutoCompleteItem> roads = devSelectHelper.getRoadListByBranchId(branchId);
            
            modelMap.put("roads", roads);
            modelMap.put("branchId", branchId);

            Map<String, List<DevNetState>> map = new HashMap<String, List<DevNetState>>();
            for (int i = 0; i < roads.size(); i++) {
                int roadId = roads.get(i).getId();
                // List<AutoCompleteItem> station = devSelectHelper
                // .getStationListByRoadId(roadId);
                // map.put(roads.get(i).getName(), station);

                List<DevNetState> list = devStateService.search(roadId);
                map.put(roads.get(i).getName(), list);

            }
            modelMap.put("map", map);
        }

        return "net/manager";
    }

}
